<template>
    <div class="component-stringRange d-flex">
        <span v-if="prefixString" class="prefixString">{{ prefixString }}</span>
        <el-input v-model="valueData.start" />
        <span class="middleString">{{ middleString }}</span>
        <el-input v-model="valueData.end" />
        <span v-if="suffixString" class="suffixString">{{ suffixString }}</span>
    </div>
</template>
<script>
export default {
    name: "com-stringRange",
    model: {
        prop: "value",
        event: "input"
    },
    props: {
        value: {
            type: Object,
            default: () => ({ start: null, end: null })
        },
        prefixString: {
            type: String,
            default: ""
        },
        middleString: {
            type: String,
            default: "-"
        },
        suffixString: {
            type: String,
            default: ""
        }
    },
    data() {
        return {
            valueData: this.value
        };
    },
    watch: {
        value: {
            deep: true,
            handler(val, oldVal) {
                if (val === oldVal) {
                    return;
                }

                this.valueData = this.value;
            }
        },
        valueData: {
            deep: true,
            handler(val, oldVal) {
                this.$emit("input", this.valueData);
            }
        }
    }
};
</script>
<style scoped lang="scss">
.component-stringRange {
     height: 28px;
    .prefixString {
        padding: 0 15px 0 0;
        flex-shrink: 0;
    }

    .middleString {
        padding: 0 15px;
        flex-shrink: 0;
    }

    .suffixString {
        padding: 0 0 0 15px;
        flex-shrink: 0;
    }
}
</style>
